long randRedF;
long randRedT;
long randGreenT;
long randBlueT;
long randGreenF;
long randBlueF;
long randCh0;
long randCh1;
long randCh2;
long randrand;
int rate = 250;
int RTcolour = 0;
int RFcolour = 0;
int GTcolour = 0;
int GFcolour = 0;
int BTcolour = 0;
int BFcolour = 0;

void RandomColours() {

   randRedF = random(0, 6);
   randRedT = random(0, 6);
   randGreenT = random(0, 6);
   randBlueT = random(0, 6);
   randGreenF = random(0, 6);
   randBlueF = random(0, 6);
   randCh0 = random(NumLEDs);
   randCh1 = random(NumLEDs);
   randCh2 = random(NumLEDs);
   
      if (randRedF == 0){
     RFcolour=1023;
   }
      if (randGreenF == 0){
     GFcolour = 1023;
   }
      if (randBlueF == 0){
     BFcolour = 1023;
   }
      if (randRedT == 0){
     GTcolour = 1023;
   }
      if (randGreenT == 0){
     GTcolour = 1023;
   }
      if (randBlueT == 0){
     BTcolour = 1023;
   }
   
   
      if (randRedF == 1){
     RFcolour = 0;
   }
      if (randGreenF == 1){
     GFcolour = 0;
   }
      if (randBlueF == 1){
     BFcolour = 0;
   }
      if (randRedT == 1){
     GTcolour = 0;
   }
      if (randGreenT == 1){
     GTcolour = 0;
   }
      if (randBlueT == 1){
     BTcolour = 0;
   }
   
   
   
      if (randRedF == 2){
     RFcolour = 750;
   }
      if (randGreenF == 2){
     GFcolour = 750;
   }
      if (randBlueF == 2){
     BFcolour = 750;
   }
      if (randRedT == 2){
     RTcolour = 750;
   }
      if (randGreenT == 2){
     GTcolour = 750;
   }
      if (randBlueT == 2){
     BTcolour = 750;
   }
   
   
   
   if (randRedF == 3){
     RTcolour = 0;
   }
      if (randGreenF == 3){
     GTcolour = 0;
   }
      if (randBlueF == 3){
     BTcolour = 0;
   }
      if (randRedT == 3){
     RTcolour = 0;
   }
      if (randGreenT == 3){
     GTcolour = 0;
   }
      if (randBlueT == 3){
     BTcolour = 0;
   }
   
   
      if (randRedF == 4){
     RFcolour = 350;
   }
      if (randGreenF == 4){
     GFcolour = 350;
   }
      if (randBlueF == 4){
     BFcolour = 350;
   }
      if (randRedT == 4){
     RTcolour = 350;
   }
      if (randGreenT == 4){
     GTcolour = 350;
   }
      if (randBlueT == 4){
     BTcolour = 350;
   }
   
   
   
      if (randRedF == 5){
     RFcolour = 0;
   }
      if (randGreenF == 5){
     GFcolour = 0;
   }
      if (randBlueF == 5){
     BFcolour = 0;
   }
      if (randRedT == 5){
     RTcolour = 0;
   }
      if (randGreenT == 5){
     GTcolour = 0;
   }
      if (randBlueT == 5){
     BTcolour = 0;
   }
   
  fadeall(20,0,0,0,RFcolour,GFcolour,BFcolour);
  fadeall(20,RFcolour,GFcolour,BFcolour,RTcolour,GTcolour,BTcolour);
  fadeall(20,RTcolour,GTcolour,BTcolour,RFcolour,GFcolour,BFcolour);

   //delay(rate);
   RandomColours();
}

// Fade between two colors at specified interval
void fadeall(int rate, int fromred, int fromgreen, int fromblue, int tored, int togreen, int toblue) {
 
 for (int i = 0; i < 33; i++) {
 
     for (int j1 = 0; j1 < NumLEDs; j1++) {
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
              
       LEDChannels[randCh0][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh2][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh1][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh1][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh0][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh2][2] = (fromblue * (32 - i) + toblue * i)/32;
       
       LEDChannels[randCh2][0] = (fromred * (32 - i) + tored * i)/32;
       LEDChannels[randCh1][1] = (fromgreen * (32 - i) + togreen * i)/32;
       LEDChannels[randCh0][2] = (fromblue * (32 - i) + toblue * i)/32;
     }
 
    WriteLEDArray();
    delay(rate);
 
   }   
}
